package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackInfoVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album")
@SuppressWarnings({"all"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;

	@Autowired
	private VodService vodService;

	@Operation(summary = "上传声音到腾讯云点播平台")
	@PostMapping(value = "/trackInfo/uploadTrack")
	public Result<Map<String,String>> uploadTrack(@RequestParam("file") MultipartFile trackFile){
		Map<String,String> tarckMap = vodService.uploadTrack(trackFile);
		return Result.ok(tarckMap);
	}

	/*
	 * 当前接口需要用户登录才能调用
	 * */
	@GuiguLogin
	@Operation(summary = "保存声音")
	@PostMapping(value = "/trackInfo/saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		Long userId = AuthContextHolder.getUserId();
		trackInfoService.saveTrackInfo(userId,trackInfoVo);
		return Result.ok();
	}

	/*
	 *当前接口需要用户登录才能调用
	 * */
	@GuiguLogin
	@Operation(summary = "获取当前用户声音分页列表")
	@PostMapping(value = "/trackInfo/findUserTrackPage/{page}/{limit}")
	public Result<Page<TrackListVo>> findUserTrackPage(
			@PathVariable Long page,
			@PathVariable Long limit,
			@RequestBody TrackInfoQuery trackInfoQuery
			){
		Long userId = AuthContextHolder.getUserId();
		trackInfoQuery.setUserId(userId);
		Page<TrackListVo> PageInfo = new Page<>(page, limit);
		PageInfo= trackInfoService.findUserTrackPage(trackInfoQuery,PageInfo);
		return Result.ok(PageInfo);
	}

	/*
	 * 当前接口需要用户登录才能调用
	 * */
	@GuiguLogin
	@Operation(summary = "修改声音信息")
	@PutMapping(value = "/trackInfo/updateTrackInfo/{id}")
	public Result updateTrackInfo(@PathVariable Long id,@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.updateTrackInfo(id,trackInfoVo);
		return Result.ok();
	}

	/*
	 *  当前接口需要用户登录才能调用
	 * */
	@GuiguLogin
	@Operation(summary = "删除声音信息")
	@DeleteMapping(value = "/trackInfo/removeTrackInfo/{id}")
	public Result removeTrackInfo(@PathVariable Long id){
		trackInfoService.removeTrackInfo(id);
		return Result.ok();
	}

}

